<html>
    <head>
        <style>
            body {
                padding: 0;
                margin: 0;
            }

            #box-a {
                width: 100px;
                height: 100px;
                background-color: #00cc88;
            }

            #box-b {
                position: absolute;
                top: 100px;
                left: 100px;
                width: 200px;
                height: 300px;
                background-color: #09f;
            }

            #trigger-overflow {
                width: 1px;
                height: 1px;
                position: absolute;
                top: 2000px;
                left: 2000px;
            }

            [data-layout-correct="false"] {
                background: #dd1144 !important;
                opacity: 0.5;
            }
        </style>
    </head>
    <body>
        <div id="box-a"></div>
        <div id="trigger-overflow"></div>

        <script type="module" src="/src/imports/projection.js"></script>
        <script type="module" src="/src/imports/script-assert.js"></script>
        <script type="module" src="/src/imports/script-animate.js"></script>
        <script type="module">
            const { createNode } = window.Animate
            const {
                matchViewportBox,
                matchVisibility,
                matchOpacity,
                matchBorderRadius,
            } = window.Assert
            const { frame } = window.Projection

            const box = document.getElementById("box-a")
            const boxProjection = createNode(
                box,
                undefined,
                { layoutId: "a" },
                { duration: 0.05 }
            )

            boxProjection.willUpdate()

            const newBox = document.createElement("div")
            newBox.id = "box-b"
            document.body.appendChild(newBox)
            const newBoxProjection = createNode(
                newBox,
                undefined,
                {
                    layoutId: "a",
                },
                { duration: 0.05 }
            )

            newBoxProjection.setValue("borderRadius", 20)

            newBoxProjection.root.didUpdate()

            const finBox = { bottom: 400, left: 100, right: 300, top: 100 }
            setTimeout(() => {
                matchViewportBox(box, finBox)
                matchViewportBox(newBox, finBox)
                matchVisibility(box, "visible")
                matchVisibility(newBox, "visible")
                // should be 0/1 instead of approximate to 0/1
                matchOpacity(box, 0)
                matchOpacity(newBox, 1)

                /**
                 * First box has an active transform applied whereas the second
                 * box doesn't. As such only the first box needs a border-radius that
                 * corrects for scale distortion.
                 */
                matchBorderRadius(box, "10% / 6.66667%")
                matchBorderRadius(newBox, "20px")
            }, 150)
        </script>
    </body>
</html>
